#pragma once

#include "e2d/core/Entity.h"
#include "fxcc/imgui/Editor.h"

#define FXCC_TREE_EDIT                                                                 \
template<typename T>                                                                   \
bool TryTreeEdit(e2d::Entity* m_Inst) {                                                \
    bool res = m_Inst->HasComponent<T>();                                              \
    bool flag{ false };                                                                \
    if (res) {                                                                          \
        std::string label = T::_Label_();                                              \
        auto& component = m_Inst->Get<T>();                                            \
                                                                                       \
        CheckBoxInst("m_Exist", component.m_Exist);                                    \
                                                                                       \
        if (ImGui::TreeNodeEx(label.c_str(),                                           \
            component.m_TreeNode ? ImGuiTreeNodeFlags_DefaultOpen : 0))               \
        {                                                                              \
            component.m_TreeNode = true;                                               \
            EditInst<T>(label, component);                                             \
            ImGui::TreePop();                                                          \
        } else {                                                                       \
            component.m_TreeNode = false;                                              \
        }                                                                              \
    }                                                                                  \
    return flag;                                                                        \
}

namespace e2d
{

    using BasicEditor = fxcc::imgui::Editor;

    struct CustomEditor
    {
        static bool ComboEditEntity(const std::string& label, e2d::EntityMap& inst, const std::vector<std::shared_ptr<e2d::Entity>> entities);

        static bool ComboEditEntity(const std::string& label, e2d::EntityMap& inst, const std::vector<e2d::EntityMap> entities);


    };
};
